import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Timestamp;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToggleButton;

public class CircleButtons extends JPanel implements TLModule{
	
	private Color BackGround = Color.WHITE;
	
	private CustomJButton user, phrase, song, list;
	private Framework fw;
	private String largeUser, largePhrase, largeSong, largeList;
	private String smallUser, smallPhrase, smallSong, smallList;
	
	public CircleButtons(Framework fm_in){
		BoxLayout layout = new BoxLayout(this,BoxLayout.Y_AXIS);
		this.setLayout(layout);
		smallUser = "Tabs_Users_small.png";
		smallPhrase = "Tabs_Phrase_small.png";
		smallSong = "Tabs_Song_small.png";
		smallList = "Tabs_List_small.png"; 
		
		largeUser = "Tabs_Users_big.png";
		largePhrase = "Tabs_Phrase_big.png";
		largeSong = "Tabs_Song_big.png";
		largeList = "Tabs_List_big.png";
		
		fw = fm_in;
		
		user = new CustomJButton(smallUser,largeUser);
		phrase = new CustomJButton(smallPhrase,largePhrase);
		song = new CustomJButton(smallSong,largeSong);
		list = new CustomJButton(smallList,largeList);
		
		class ButtonListener implements ActionListener{
			public void actionPerformed(ActionEvent e) {
				CustomJButton cb = (CustomJButton) e.getSource();
				if (cb.equals(user)){
					reset();
					user.setIcon(new ImageIcon(largeUser));
					// TODO
					fw.userState();
				}
				else if (cb.equals(phrase)){
					reset();
					phrase.setIcon(new ImageIcon(largePhrase));
					// TODO 
					fw.phraseState();
				}
				else if (cb.equals(song)){
					reset();
					song.setIcon(new ImageIcon(largeSong));
					// TODO
					fw.songState();
				}
				else if (cb.equals(list)){
					reset();
					list.setIcon(new ImageIcon(largeList));
					// TODO 
					fw.listState();
				}
			}
		}
		ButtonListener listener = new ButtonListener();
		
		user.addActionListener(listener);
		phrase.addActionListener(listener);
		song.addActionListener(listener);
		list.addActionListener(listener);
		
		this.setBackground(BackGround);
		
		add(user);
		add(phrase);
		add(song);
		add(list);
		
		
		list.setIcon(new ImageIcon(largeList));
	}
	
	private class CustomJButton extends JToggleButton{
		public CustomJButton(String image,String bigimage){
			this.setBorderPainted(false);
			ImageIcon smallIcon = new ImageIcon(image);
			this.setIcon(smallIcon);
			this.setContentAreaFilled(false);
			this.setFocusPainted(false);
		}
	}
	
	@Override
	public void highlightPhrase(List<Long> phraseId) {
		reset();
		phrase.setIcon(new ImageIcon(largePhrase));
	}

	@Override
	public void highlightSong(List<Long> songId) {
		reset();
		song.setIcon(new ImageIcon(largeSong));
	}

	@Override
	public void highlightUser(List<String> users) {
		reset();
		user.setIcon(new ImageIcon(largeUser));
	}

	@Override
	public void reset() {
		user.setIcon(new ImageIcon(smallUser));
		phrase.setIcon(new ImageIcon(smallPhrase));
		list.setIcon(new ImageIcon(smallList));
		song.setIcon(new ImageIcon(smallSong));
	}

	@Override
	public void resetBillBoard(String chartName) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resetPhrase() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resetSong() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resetTime() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resetUser() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setBillBoard(String chartName) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setPhrase(List<Long> phraseId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setSong(List<Long> songId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setTimeSpan(Timestamp start, Timestamp end) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setUser(List<String> users) {
		// TODO Auto-generated method stub
		
	}

	public static void main(String Args[]){
		JFrame frame = new JFrame("buttons");
		frame.setSize(200, 200);
		frame.add(new CircleButtons(null));
		frame.setVisible(true);
		frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
	}
}
